<style>
    .channeltag {
        background-color: #ff5722;
        color: #fff;
        padding: 4px;
        border-radius: 4px;
        margin-right: 8px;
    }
</style>
<div class="rightcontent rc-bg-grey">
    <div class="rc-pagepadding">
        <div class=" rc-pannel ">
            <div class=" rc-pannel-header">
                <div class="rc-flex layui-form toolbar rc-flex-justify-between">
                    <div class=" rc-flex rc-flex-vertical-center ">
                    </div>
                    <div>
                        <a href="/admin/cnf/Message/addTemplate" class="layui-btn layui-btn-primary layui-btn-sm"><i class="iconfont">&#xe60e;</i> 添加模板</a>
                    </div>
                </div>
            </div>

            <div class="rc-pannel-body layui-form rc-pagepadding ">
                <table class="layui-table">
                    <colgroup>
                        <col>
                        <col>
                        <col>
                        <col>
                        <col style="width: 240px;">

                    </colgroup>
                    <thead>
                        <tr>
                            <th>挂载事件动作</th>
                            <th>标题</th>
                            <th>内容</th>
                            <th>发送通道</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php

                        foreach ($templates as $template) {
                        ?>
                            <tr>
                                <td>
                                    <?php echo $template->hookident; ?>
                                </td>
                                <td> <?php echo $template->title; ?></td>
                                <td> <?php echo $template->content; ?></td>
                                <td>
                                    <?php
                                    if ($template->channel) {
                                        $tempchannels = explode(',', trim($template->channel, ','));
                                        foreach ($tempchannels as $tempchannel) {
                                            if (isset($channels[$tempchannel])) {
                                    ?>
                                                <span class="channeltag"><?php echo $channels[$tempchannel]['title'] ?></span>
                                            <?php
                                            }
                                            ?>

                                    <?php
                                        }
                                    }

                                    ?>
                                </td>
                                <td>

                                    <div class="rc-opbar">
                                        <a class="info" href="/admin/cnf/Message/editTemplate?id=<?php echo $template->id ?>"><i class="iconfont">&#xe606;</i> 编辑</a>
                                        <a class="error delete" templateid="<?php echo $template->id ?>"><i class="iconfont">&#xe607;</i> 删除 </a>
                                    </div>

                                </td>
                            </tr>
                        <?php
                        }
                        ?>

                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(function() {
        var layer = layui.layer;

        $('.delete').click(function() {
            var templateid = $(this).attr('templateid');
            layer.confirm('确定要删除么？', {
                icon: 3
            }, function() {
                $.ajax({
                    url: '/admin/cnf/Message/delTemplate?id=' + templateid, //请求路径
                    type: "POST", //请求方式
                    success: function(data) {
                        if (data.code == 0) {
                            window.location.reload();
                        } else {
                            toastr_error(data.message);
                        }
                        layer.closeAll();
                    },
                    error: function() {
                        layer.closeAll();
                    },

                });


            }, function() {



            });

        });

    });
</script>